<!--意向申报-->
<template>
  <div>
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane label="表单" name="first">
        <div class="top-title">意向申报</div>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-row>
            <el-col :span="6">
              <el-form-item label="申报人：" prop="responsiblePerson">
                <el-input v-model="ruleForm.responsiblePerson"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="申报日期：" prop="date">
                <el-input v-model="ruleForm.date"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="申报部门：" prop="depart">
                <el-input v-model="ruleForm.depart"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="№：" prop="number">
                <el-input v-model="ruleForm.number"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="申报单位：" prop="unit">
                <el-input v-model="ruleForm.unit"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="tab-part">
            <span class="part-line"></span>
            <span class="part-title">基本信息</span>
          </div>
          <el-row>
            <el-col :span="12">
              <el-form-item label="项目名称：" prop="entryName">
                <el-input v-model="ruleForm.entryName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="项目编号：" prop="entryId">
                <el-input v-model="ruleForm.entryId"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="资金来源：" prop="source">
                <el-input v-model="ruleForm.source"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="项目类型：" prop="entryType">
                <el-input v-model="ruleForm.entryType"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="负责人：" prop="responsiblePerson">
                <el-input v-model="ruleForm.responsiblePerson"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="项目部门：" prop="depart">
                <el-input v-model="ruleForm.depart"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="预计收入：" prop="income">
                <el-input v-model="ruleForm.income"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="事由及说明：" prop="explanation">
                <el-input v-model="ruleForm.explanation"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="相关附件：" prop="annex">
                <el-input v-model="ruleForm.annex"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="tab-part">
            <span class="part-line"></span>
            <span class="part-title">审批意见</span>
          </div>
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入审批意见"
            v-model="ruleForm.approval">
          </el-input>
          <div v-if="ModalType=='add'" style="display: flex;justify-content: flex-end;margin-top: 16px">
            <el-button @click="closeModal">取 消</el-button>
            <el-button type="primary" @click="save('ruleForm')" >保 存</el-button>
          </div>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="流程" name="second">
        流程
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
export default {
  name: 'intentionalDeclaration',
  data(){
    return{
      activeName: 'first',
      ruleForm: {
        responsiblePerson: '',
        date: '',
        depart: '',
        number: '',
        unit:'',
        entryName:'',
        entryId:'',
        source:'',
        entryType:'',
        income:'',
        explanation:'',
        annex:'',
        approval:''
      },
      rules: {
        responsiblePerson: [
          { required: true, message: '请输入合同名称', trigger: 'blur' },
          { max: 20, message: '长度最大20个字符', trigger: 'blur' }
        ],
        date: [
          { required: true, message: '请输入合同编号', trigger: 'blur' }
        ],
      }
    }
  },
  props: {
    row: {
      type: Object,
      default: () => {
      }
    },
    //关闭弹窗
    closeModal: {
      type: Function,
      default: null
    },
    ModalType:{
      type: String,
      default: ''
    }
  },
  watch: {
    row(n) {
      if (Object.keys(n).length !== 0) {
        this.ruleForm = Object.assign({}, n)
      }
    }
  },
  mounted() {
    if (Object.keys(this.row).length !== 0) {
      this.ruleForm = Object.assign({}, this.row)
    }
  },
  methods:{
    handleClick(tab, event) {
      console.log(tab, event);
    },

    save(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$message.success('保存成功！')
          this.closeModal();
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
.top-title {
  font-size: 24px;
  font-weight: bold;
  color: #ffffff;
  background: #1ab394;
  padding: 16px;
  align-items: center;
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}
.tab-part {
  display: flex;
  align-items: center;
  border-bottom: 2px solid #e7eff3;
  padding-bottom: 10px;
  margin-bottom: 16px;

  .part-line {
    display: inline-block;
    width: 4px;
    height: 16px;
    background-color: #1ab394;
    float: left;
    margin-top: 2px;
    margin-right: 10px;
  }

  .part-title {
    font-weight: bold;
  }
}
</style>
